#pragma once

#ifndef _CR_MD5_UTILSS_H_
#define _CR_MD5_UTILSS_H_

NS_CR_BEGIN

namespace utils 
{
	class md5_engine 
	{
		typedef struct __context_t
		{
			uint32_t state[4];								/* state (ABCD) */
			uint32_t count[2];								/* number of bits, modulo 2^64 (lsb first) */
			unsigned char buffer[64];						/* input buffer */
		} context_t;
	public:
		md5_engine();
		char* digest_memory(void *memchunk, int len);
		char* digest_file(const char* filename);
	private:
		void init();
		void update(const uint8_t* input, uint32_t input_len);
		void final();
		void to_string();
	private:
		uint8_t _digest_raw[16];
		char	_digest_chars[33];
		context_t context;
	};

	namespace md5 
	{
		CR_DLL tstring digest_memory(void *memchunk, int len);
		
		CR_DLL tstring digest_string(const tstring& str);

		CR_DLL tstring digest_file(const tstring& filename);
	}
}

NS_CR_END

#endif // !_CR_MD5_UTILSS_H_
